﻿using System;
using System.Collections.Generic;
using Gp.Scripts.Equip;
using Sirenix.OdinInspector;

namespace Gp.Scripts.Data {
    [Serializable]
    public abstract class MeleeBaseWeaponType : BaseWeaponType {
        public static readonly List<int> MeleePos = new() {0, 1};

        private const int TargetNum = 2;

        [LabelText("武器伤害")] [OnValueChanged("UpdateDamage")]
        public int damage = 1;

        [LabelText("穿透")] public int breakThrough;

        [LabelText("耐久度")] public int durability = 3;

        [ToggleGroup("canCharge", "能否充能")] public bool canCharge;

        [BoxGroup("canCharge/Data", false)] [LabelText("充能伤害")] [MinValue("damage")]
        public int chargeDamage = 10;


        [BoxGroup("canCharge/Data")] [LabelText("穿透"), MinValue(0)]
        public int chargeBreakthrough = 1;


        // public override StatField RequireStat => StatField.MaxHealth;

        public override WeaponBasicType WeaponBasicType => WeaponBasicType.Melee;


        // /// <summary>
        // /// 近战武器目标选择：
        // /// 1、发起者需要位于1、2号位
        // /// 2、近战武器在对方1、2号位有人时，只能对1、2号位的敌方单位进行攻击。
        // /// </summary>
        // public override List<AttachCell> GetTargets(UnitAbilityContext context) {
        //     var res = new List<AttachCell>();
        //     // 当前单位位置
        //     var unitPos = context.UnitPos.Index;
        //     // 如果不在近战攻击位
        //     if (!MeleePos.Contains(unitPos))
        //         return res;
        //
        //
        //     var temp = TargetNum - unitPos;
        //
        //     // 在范围内、且位于近战位的目标，最多为2名
        //     var placeHolder = CellGridSystem.Instance.PlaceHolder;
        //
        //
        //     // 当对方近战位有单位时，只能攻击近战位
        //     for (int i = 0; i < MeleePos.Count; i++) {
        //         var unit = placeHolder.GetUnit(context.Targets[i]);
        //         if (unit != null) res.Add(context.Targets[i]);
        //     }
        //
        //
        //     if (res.Count > 0) return res;
        //
        //     // 将其他单位添入结果中
        //     foreach (var cell in context.Targets) {
        //         var unit = placeHolder.GetUnit(cell);
        //         if (unit == null) continue;
        //
        //         res.Add(cell);
        //         if (res.Count >= temp) {
        //             break;
        //         }
        //     }
        //
        //     return res;
        // }

        public override WeaponTypeInfo BuildInfo(WeaponEntity entity) {
            return new MeleeWeaponInfo(this, entity);
        }

#if UNITY_EDITOR
        private void UpdateDamage() {
            chargeDamage = Math.Max(chargeDamage, damage);
        }
#endif
    }
}